package config

import (
	"github.com/hwcer/cosgo/random"
	"github.com/hwcer/yyds"
)

const (
	ActiveRandomName = "ActiveConfigRandomName"
)

func init() {
	yyds.Config.Register(&activeHandle{})
}

type ActiveRandom struct {
	c                 *output
	MonthSignRateGift map[int32]*random.Random
}

func GetActiveRandom() *ActiveRandom {
	return yyds.Config.Process.Get(ActiveRandomName).(*ActiveRandom)
}

type activeHandle struct {
	HandleDefault
}

func (this *activeHandle) Handle(c *yyds.CS, i any) {
	data := i.(*output)
	g := &ActiveRandom{c: data}
	//月签到今日运势
	g.MonthSignRateGift = map[int32]*random.Random{}
	for _, d := range data.MonthSignRateGift {
		v, ok := g.MonthSignRateGift[d.Group]
		if !ok {
			v = &random.Random{}
			g.MonthSignRateGift[d.Group] = v
		}
		v.Add(d.Id, d.Rate)
	}

	c.Process.Set(ActiveRandomName, g)

}
